package com.lanchewuyou.user.driver.lipeiui;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;

import com.lanchewuyou.user.driver.R;
import com.lanchewuyou.user.driver.layouts.FixItemLayout;

import java.util.ArrayList;
import java.util.List;

/**
 * 动态显示维修详情界面，根据传来的type和数组显示是否维修
 */

public class FixInforActivity extends AppCompatActivity {
    private Toolbar mToolbar;
    private TextView titleText;
    private FixItemLayout fixQiangang,fixZuoQianyezi,fixZuoqianmen,fixZuohoumen,
            fixNoZuohouyeziban,fixJigai,fixZuofanguangjing,fixYouhoumen,fixYouqianmen,
            fixYouqianyeziban,fixHougai,fixZuodabian,fixYoudabian,fixYoufanguangjing,
            fixZuoqianlungu,fixZuohoulungu,fixYouqianlungu,fixYouhoulungu,
            fixHougang,fixYouhouyeziban;
    String[] itemLists=new String[]{"前杠","左前叶子板","左前门","左后门","左后叶子板","机盖","左反光镜","右后门",
            "右前门","右前叶子板","后盖","左大边","右大边","右反光镜","左前轮毂","左后轮毂","右前轮毂","右后轮毂","后杠","右后叶子板"};

    List<FixItemLayout> fixItemLayoutList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fix_infor);
        mToolbar = (Toolbar) findViewById(R.id.toolbar);
        titleText = (TextView) findViewById(R.id.titletype_text);
        initLayout();
        initLists();
        //根据维修页面传来的数据类型确定维修详情界面
        Bundle bundle = this.getIntent().getExtras();
        String title = bundle.getString("type");
        if (title.equals("huahen")) {
            int[] fixnot = bundle.getIntArray("huahennonum");
            int[] fixyes = bundle.getIntArray("huahenyesnum");
            mToolbar.setTitle("车辆划痕情况");
            setSupportActionBar(mToolbar);
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setHomeButtonEnabled(true);
            titleText.setText("划痕位置");
            for (int i = 0; i < 20; i++) {
                fixItemLayoutList.get(i).setTitleText(itemLists[i]);
                fixItemLayoutList.get(i).setIsFix(fixyes[i]);
                fixItemLayoutList.get(i).setIsNotFix(fixnot[i]);
            }
        } else if (title.equals("banjin")) {
            int[] fixnot = bundle.getIntArray("banjinnonum");
            int[] fixyes = bundle.getIntArray("banjinyesnum");
            mToolbar.setTitle("车辆钣金情况");
            setSupportActionBar(mToolbar);
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setHomeButtonEnabled(true);
            titleText.setText("钣金位置");
            for (int i = 0; i < 20; i++) {
                fixItemLayoutList.get(i).setTitleText(itemLists[i]);
                fixItemLayoutList.get(i).setIsFix(fixyes[i]);
                fixItemLayoutList.get(i).setIsNotFix(fixnot[i]);
            }

        }else if(title.equals("penqi")) {
            int[] fixnot = bundle.getIntArray("penqinonum");
            int[] fixyes = bundle.getIntArray("penqiyesnum");
            mToolbar.setTitle("车辆喷漆情况");
            setSupportActionBar(mToolbar);
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setHomeButtonEnabled(true);
            titleText.setText("喷漆位置");
            for (int i = 0; i < 20; i++) {
                fixItemLayoutList.get(i).setTitleText(itemLists[i]);
                fixItemLayoutList.get(i).setIsFix(fixyes[i]);
                fixItemLayoutList.get(i).setIsNotFix(fixnot[i]);
            }

        }else{
            Toast.makeText(this, "  ", Toast.LENGTH_SHORT).show();
        }
    }

    private void initLayout(){
        fixQiangang=(FixItemLayout)findViewById(R.id.fixitem_qiangang);
        fixZuoQianyezi=(FixItemLayout)findViewById(R.id.fixitem_zuoqianyezi);
        fixZuoqianmen=(FixItemLayout)findViewById(R.id.fixitem_zuoqianmen);
        fixZuohoumen=(FixItemLayout)findViewById(R.id.fixitem_zuohoumen);
        fixNoZuohouyeziban=(FixItemLayout)findViewById(R.id.fixitem_zuohouyezi);
        fixJigai=(FixItemLayout)findViewById(R.id.fixitem_jigai);
        fixZuofanguangjing=(FixItemLayout)findViewById(R.id.fixitem_zuofanguangjing);
        fixYouhoumen=(FixItemLayout)findViewById(R.id.fixitem_youhoumen);
        fixYouqianmen=(FixItemLayout)findViewById(R.id.fixitem_youqianmen);
        fixYouqianyeziban=(FixItemLayout)findViewById(R.id.fixitem_youqianyezi);
        fixHougai=(FixItemLayout)findViewById(R.id.fixitem_hougai);
        fixZuodabian=(FixItemLayout)findViewById(R.id.fixitem_zuodabian);
        fixYoudabian=(FixItemLayout)findViewById(R.id.fixitem_youdabian);
        fixYoufanguangjing=(FixItemLayout)findViewById(R.id.fixitem_youfanguangjing);
        fixZuoqianlungu=(FixItemLayout)findViewById(R.id.fixitem_zuoqianlungu);
        fixZuohoulungu=(FixItemLayout)findViewById(R.id.fixitem_zuohoulungu);
        fixYouqianlungu=(FixItemLayout)findViewById(R.id.fixitem_youqianlungu);
        fixYouhoulungu=(FixItemLayout)findViewById(R.id.fixitem_youhoulungu);
        fixHougang=(FixItemLayout)findViewById(R.id.fixitem_hougang);
        fixYouhouyeziban=(FixItemLayout)findViewById(R.id.fixitem_youhouyezi);

    }
    private void initLists(){
        fixItemLayoutList=new ArrayList<FixItemLayout>();
        fixItemLayoutList.add(fixQiangang);
        fixItemLayoutList.add(fixZuoQianyezi);
        fixItemLayoutList.add(fixZuoqianmen);
        fixItemLayoutList.add(fixZuohoumen);
        fixItemLayoutList.add(fixNoZuohouyeziban);
        fixItemLayoutList.add(fixJigai);
        fixItemLayoutList.add(fixZuofanguangjing);
        fixItemLayoutList.add(fixYouhoumen);
        fixItemLayoutList.add(fixYouqianmen);
        fixItemLayoutList.add(fixYouqianyeziban);
        fixItemLayoutList.add(fixHougai);
        fixItemLayoutList.add(fixZuodabian);
        fixItemLayoutList.add(fixYoudabian);
        fixItemLayoutList.add(fixYoufanguangjing);
        fixItemLayoutList.add(fixZuoqianlungu);
        fixItemLayoutList.add(fixZuohoulungu);
        fixItemLayoutList.add(fixYouqianlungu);
        fixItemLayoutList.add(fixYouhoulungu);
        fixItemLayoutList.add(fixHougang);
        fixItemLayoutList.add(fixYouhouyeziban);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_custom_infor, menu);
        return true;
    }
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == android.R.id.home) {
            finish();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
